package farmer.game;

import java.util.ArrayList;

import farmer.core.Building;
import farmer.core.Unit;
import farmer.render.building.City;
import farmer.render.building.Farm;
import farmer.render.building.House;
import farmer.render.building.LumberCamp;
import farmer.render.building.Mine;
import farmer.render.building.Road;
import farmer.render.building.Windmill;
import farmer.update.doodad.Tree;

public class Data {
	
	public static int running = 0;
	public static int failed = 1;
	public static int victory = 2;
	public static int paused = 3;
	
	public static int status = running;
	
	public static int food = 0;
	public static int rock = 0;
	public static int wood = 0;
	
	public static int building = -1;
	public static ArrayList<Unit> selectedUnitList = new ArrayList<Unit>();
	
	public static final int none = -1;
	public static final int city = 0;
	public static final int farm = 1;
	public static final int windmill = 2;
	public static final int lumbercamp = 3;
	public static final int mine = 4;
	public static final int house = 5;
	public static final int road = 6;
	public static final int tree = 7;
	public static final int destroy = 8;
	
	public static boolean hasRessourceToBuild(){
		if(building == destroy){
			return true;
		}else if(building == tree){
			return wood >= Tree.woodCost;
		}else{
			Building build = getBuilding(0, 0, Data.building);
			if(build != null){
				return wood >= build.getWoodCost() && rock >= build.getRockCost();
			}
		}
		return false;
	}
	
	public static boolean hasRessourceToBuild(int w, int r, int b){
		if(b == destroy){
			return true;
		}else if(b == tree){
			return w >= Tree.woodCost;
		}else{
			Building build = getBuilding(0, 0, b);
			if(build != null){
				return w >= build.getWoodCost() && r >= build.getRockCost();
			}
		}
		return false;
	}
	
	public static int getSize(int type){
		switch(type){
		case city: return 5;
		case farm: return 4;
		case windmill: return 3;
		case lumbercamp: return 3;
		case mine: return 3;
		case house: return 2;
		case road: return 1;
		case tree: return 1;
		}
		return 0;
	}
	
	public static Building getBuilding(int x, int y, int type){
		switch(type){
		case city: return new City(x, y);
		case farm: return new Farm(x, y);
		case windmill: return new Windmill(x, y);
		case lumbercamp: return new LumberCamp(x, y);
		case mine: return new Mine(x, y);
		case house: return new House(x, y);
		case road: return new Road(x, y);
		}
		return null;
	}

}
